<template>
  <div>
    <fks-query-page
      v-loading="listLoading"
      :data="tableData"
      :total="total"
      :page-size.sync="pageSize"
      :current-page.sync="currentPage"
      layout="total, sizes, prev, pager, next, jumper"
      :page-sizes="[20, 50, 100]"
      :element-loading-text="LANG.LOADING"
      :table-name="LANG.BEHAVIOR_DATA"
      @query="getData"
      @sort-change="sortHandler"
    >
      <template>
        <fks-table-column
          type="index"
          align="center"
          label="#"
        >
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </fks-table-column>
        <fks-table-column
          prop="userName"
          :label="LANG.USERNAME"
          min-width="120"
        />
        <fks-table-column
          prop="userFullname"
          :label="LANG.USER_FULL_NAME"
          min-width="120"
          align="center"
          sortable="custom"
        />
        <fks-table-column
          prop="ev"
          :label="LANG.EVENT"
          min-width="100"
          align="center"
        />
        <fks-table-column
          prop="fun"
          :label="LANG.FUN"
          width="180"
          align="left"
        />
        <fks-table-column
          prop="createTime"
          :label="LANG.TRIGGED_TIME"
          sortable="custom"
          width="180"
        />
        <fks-table-column
          prop="mc"
          :label="LANG.MODULE_CODE"
          width="150"
          align="left"
        />
        <fks-table-column
          prop="mn"
          :label="LANG.MODULE_NAME"
          width="140"
          align="left"
        />
        <fks-table-column
          prop="fn"
          :label="LANG.PRE_MODULE_NAME"
          width="140"
          align="left"
        />
        <fks-table-column
          prop="fc"
          :label="LANG.PRE_MODULE_CODE"
          width="150"
          align="left"
        />
        <!-- <fks-table-column
          prop="md"
          label="请求数据"
          align="left"
          min-width="200"
        >
        </fks-table-column> -->
        <!-- <fks-table-column
          prop="nt"
          :label="LANG.NT"
          min-width="80"
        /> -->
        <fks-table-column
          prop="sr"
          :label="LANG.SR"
          min-width="180"
        />
      </template>
    </fks-query-page>
  </div>
</template>
<script>
import Mix from '@/mixins/module'
import * as user from './api'
export default {
  name: 'Behavior',
  mixins: [Mix],
  data() {
    return {
      pageSize: 20,
      currentPage: 1,
      total: 0,
      tableData: [],
      listLoading: false,
      sortType: '',
      sortName: ''
    }
  },
  created() {
    this.getData()
  },
  methods: {
    sortHandler(data) {
      let params = {}
      if (!data.order) {
        this.sortType = ''
        this.sortName = ''
      } else {
        this.sortType = data.order === 'ascending' ? 'asc' : 'desc'
        this.sortName =
          data.prop === 'user_fullname' ? 'user_fullname' : 'create_time'
      }
      params = {
        page: this.currentPage,
        size: this.pageSize,
        sortName: this.sortName,
        sortType: this.sortType
      }
      this.listLoading = true
      this.getDataList(params)
    },
    getData() {
      this.listLoading = true
      let params = {
        page: this.currentPage,
        size: this.pageSize
      }
      this.getDataList(params)
    },
    getDataList(params) {
      user
        .getData(params)
        .then((res) => {
          if (res.status && res.data) {
            this.tableData = res.data.list
            this.total = res.data.total
          }
          this.listLoading = false
        })
        .catch(() => {
          this.listLoading = false
        })
    }
  }
}
</script>
<style lang="scss" scoped>
</style>